package com.timothy.android.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ValueCopyUtil {
	public static void valueCopy(Object fatherObj, Object childObj) throws Exception {
		Class<?> objFirstClass = fatherObj.getClass();
		Class<?> objTwoClass = childObj.getClass();

		Field[] field = objFirstClass.getDeclaredFields();
		
		for (int i = 0; i < field.length; i++) {
			String fieldName = field[i].getName();
			String firstEdh = fieldName.substring(0, 1).toUpperCase();
			String setMethodName = "set" + firstEdh + fieldName.substring(1);
			String getMethodName = "get" + firstEdh + fieldName.substring(1);
			Method getMethod = objFirstClass.getMethod(getMethodName,
					new Class[] {});
			Method setMethod = objTwoClass.getMethod(setMethodName,
					new Class[] { field[i].getType() });
			Object value = getMethod.invoke(fatherObj, new Object[] {});
			setMethod.invoke(childObj, new Object[] { value });

		}

	}
}
